<?php
/**
 *  
 * @package Nokia Places Plugin
 * @title Core placesapi page
 * @author Nikolai Tihhomirov
 *	
 * Searching for a place
 * Picking from a list
 * Inserting particular place
 * 
 */
 //include wp-load.php
require_once( dirname( dirname( dirname( __FILE__ ) ) ) . '/placesapi_config.php');
//check rights
if ( !current_user_can( 'edit_pages' ) && !current_user_can( 'edit_posts' ) ) 
	wp_die( __( "You are not allowed to be here" ) );
global $wpdb;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<!--Insert core js and stylesheets -->
	<script type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-content/plugins/nokia-places-plugin/placesapi/jsPlacesAPI-en_GB.js"></script>
	<script type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-content/plugins/nokia-places-plugin/placesapi/configuration.js"></script>
	<script src='<?php echo get_option('siteurl') ?>/wp-includes/js/jquery/jquery.js'></script>
    <script src='<?php echo get_option('siteurl') ?>/wp-content/plugins/nokia-places-plugin/tinymce/colorbox/jquery.colorbox.js'></script>
    <script type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-content/plugins/nokia-places-plugin/tinymce/page/js/core.js"></script>
	<link rel="stylesheet" type="text/css" media="all" href="<?php echo get_option('siteurl') ?>/wp-content/plugins/nokia-places-plugin/templates/custom/custom.css" />
	</head>
    <body>
	<style>
	  .nokia-places-general-placelist .nokia-place-name{
          cursor: pointer;
		}
	</style>
	<!--Include custom template container -->
<?php include_once ( dirname( dirname( dirname ( __FILE__ ) ) ) . '/templates/custom/custom.html');?>
			<!--Core places api table -->
		  <table cellspacing="2" id="content">
            <tr>
              <td valign="top">
                    <div id="searchBox"></div>
             		<div id="placeList"></div>
                </td>
                <td id="widget_place" valign="top">
				
				<p align="center">Choose a template:</p>
				<p align="center"><input rel="template" type="radio" name="group1" value="default" checked>Default
				<input rel="template" type="radio" name="group1" value="custom" >Custom
				</p>
				<p align="center"><input class="insert_place" type="button" Value="Insert" style="position:relative;"></p>
				
				 <div id="placeWidget"></div>
				</td>                        
            </tr>
        </table>
     
<script type="text/javascript">
            
			var placeWidget = new nokia.places.Place({
                				targetNode: 'placeWidget'							
            			});
			
            var placeList = new nokia.places.PlaceList({
                targetNode: 'placeList',
				perPage: 9,
				events: [
				{
					rel:'nokia-place-name',
					name:'click',
					handler: function( data ){
						placeWidget.setPlaceId( data.placeId );
						//resizing according to placeWidget
						new_placewidget_resize();											
					}
				}
				]
            });
            
            var searchBox = new nokia.places.SearchBox({
                targetNode: 'searchBox',
                searchCenter: function () {
                    return {
                        latitude: 52.516274,
                        longitude: 13.377678
                    }
                },
                onResults: function ( data ) {
                    placeList.setData( data );
                }
               
            });
        </script>
    </body>
</html>